package cn.edu.ldk.serviceImpl;

import cn.edu.ldk.common.CommonJsonResult;
import cn.edu.ldk.mapper.AddressMapper;
import cn.edu.ldk.pojo.Address;
import cn.edu.ldk.service.AddressService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.annotation.Resources;
import java.util.List;

@Service
public class AddressServiceImpl implements AddressService {
//    @Autowired(required = false)
    @Resource
    private AddressMapper addressMapper;//注入持久层对象


    @Override
    public List<Address> findAllAddress() {
        QueryWrapper<Address> queryWrapper=new QueryWrapper<>();
        List<Address> list = addressMapper.selectList(queryWrapper);
        return list;
    }

    @Override
    public CommonJsonResult<Void> save(Address address) {
        int row = addressMapper.insert(address);
        if(row!=1){
            return new CommonJsonResult<>(201,"添加失败");
//            return new CommonJsonResult<>(201,"添加失败",null);
        }
        return new CommonJsonResult<>(200,"添加成功");
    }

    @Override
    public CommonJsonResult<Address> getAddressinfoByid(Integer id) {
        //判断参数
        if(id==null){
            return new CommonJsonResult<>(201,"该数据不存在");
        }
        Address address = addressMapper.selectById(id);
        return new CommonJsonResult<>(200,"查询成功",address);
    }
}
